+(function($){
	var btnDefaults=[],bodyDefaults=[],icon='',settings;
	var BtnObj = function(opt){
        this.btnDefaults = [
            {title:"编辑",icon:"fa fa-edit",fun:"edit"},
			{title:"删除",icon:"fa fa-trash-o",fun:"del"}
			];
        this.options  = $.extend({},this.btnDefaults,opt);
	}
	BtnObj.prototype = { 
		setBtnObj:function(){
			var iconHtml='';
			$.each(this.options,function(i,item){
				if(!isNaN(i)){
					iconHtml+='<a title="'+item.title+'" onclick="'+item.fun+'(this)"><i class="'+item.icon+'"></i></a>';
				}
			})
			return iconHtml;
		}
	}

	$.formatDate = function(date){
		var myyear = date.getFullYear();
        var mymonth = date.getMonth();
        var myweekday = date.getDate();

        if(mymonth < 10){
            mymonth = "0" + mymonth;
        }
        if(myweekday < 10){
            myweekday = "0" + myweekday;
        }
        return (myyear+"-"+mymonth + "-" + myweekday);
	}
	$.get_month = function(){
        var thisMonth = new nowDate();
        return thisMonth.nowYear+'-' + (thisMonth.nowMonth <10 ? '0'+thisMonth.nowMonth : thisMonth.nowMonth) + '-01';
    }
    $.get_today = function(){
        var thisToday = new nowDate();        
        return thisToday.nowYear + '-' + (thisToday.nowMonth <10 ? '0'+thisToday.nowMonth : thisToday.nowMonth) + '-' + (thisToday.nowDay <10 ? '0'+thisToday.nowDay : thisToday.nowDay);
    }
	
	$.fn.setList=function(json,btnArr,icon){
		var listHtml='';
		((icon=='' || icon==undefined || icon==null) ? icon='fa-file-text-o':'');
		var btnObj = new BtnObj(btnArr);
		var btnHtml=btnObj.setBtnObj()
		$.each(json,function(i,item){
			listHtml+='<li class="col-md-6 col-lg-4 col-sm-12 col-xs-12">'+
						'	<div class="role-item">'+
						'		<div class="item-logo"><div class="item-i"><i class="fa '+icon+'" style="font-size:80px;color:#898989;"></i></div></div>'+
						'		<div class="item-body">'+
						'			<div class="body-head">'+
						'				<span id="item-id" style="display:none">'+item.id+'</span>'+
						'				<span id="user-id" style="display:none">'+item.userid+'</span>'+
						                    '<div class="item-head">'+ $.setHead(item)+'</div>'+
						   '				<div class="item-btns">'+'<div class="innerbtn">'+btnHtml+'</div>'+'</div>'+
						'			</div>'+
						'			<div class="body-body">'+$.setBody(item)+'</div>'+
						'		</div>'+
						'	</div>'+
						'</li>'
		})
		$(this).append(listHtml);
	}
	$.fn.setStatistics = function(num,data){
		var statisticsLi='';
		var liWidth=100/num;
		$.each(data,function(i,item){
			statisticsLi += '<li style="width:'+liWidth+'%" id="'+item.id+'" title="'+item.title+'" url="'+item.url+'" onclick="click_jump(this)">'+
								'<div class="'+item.color+'">'+
									'<div class="left-icon">'+
										'<i class="fa '+item.icon+'"></i>'+
									'</div>'+
									'<div class="right-num">'+
										'<h3>'+item.value+'</h3>'+
										'<span>'+item.text+'</span>'+
									'</div>'+
								'</div>'+
							'</li>'
			
		})
		$(this).append(statisticsLi);
		
	}
	$.fn.placeholder = function () {
    	
        // var opts = $.extend({}, $.fn.placeholder.defaults, options);
        var isIE = document.all ? true : false;
        this.each(function () {
            var _this = this, placeholderValue = _this.getAttribute("placeholder"); //缓存默认的placeholder值
            if(_this.getAttribute("value") == null && placeholderValue!=null && isIE){
            	_this.setAttribute("value", placeholderValue);
                _this.onfocus = function () {
                    $.trim(_this.value) == placeholderValue ? _this.value = "" : '';
                };
                _this.onblur = function () {
                    $.trim(_this.value) == "" ? _this.value = placeholderValue : '';
                };
            }
        });
    };
	$.extend({
		setHead:function(arr){
			var headHtml='';
			if(!arr.k && !arr.name && !arr.appname && arr.uname){
				((arr.uname && arr.uname!='') ? headHtml+='<h4 class="head-name" title="'+arr.uname+'">'+arr.uname+'</h4>':'');//用户管理
			}else if(!arr.k &&arr.appname){
				((arr.appname && arr.appname!='') ? headHtml+='<h4 class="head-name" title="'+arr.appname+'"">'+arr.appname+'</h4>':'');
			}else if(arr.k){
				((arr.k && arr.k!='') ? headHtml+='<h4 class="head-name" title="'+arr.k+'">'+'k：'+arr.k+'</h4>':'');
			}else{
				((arr.name && arr.name!='') ? headHtml+='<h4 class="head-name" title="'+arr.name+'">'+arr.name+'</h4>':'');
			}
			return headHtml;
		},
		setBody:function(arr){
			// debugger;
			var bodyHtml='';	
			 
		    if(arr.name || arr.url){
		    	
		    	((arr.port && arr.port!='') ? bodyHtml+='<p>'+'端口：'+arr.port+'</p>':'');

                // ((arr.k && arr.k!='') ? bodyHtml+='<p">'+'传感器编号：'+arr.k+'</p>':'');
                ((arr.k && arr.k!='') ? bodyHtml+='<p>'+'传感器名称：'+arr.name+'</p>':''); //私协字典
                
		   		((arr.tname && arr.tname!='') ? bodyHtml+='<p>'+'数据类型：'+arr.tname+'</p>':'');	
		   		((arr.uname && arr.uname!='') ? bodyHtml+='<p>'+'用户：'+arr.uname+'</p>':'');	
		   		((arr.pushurl) ? bodyHtml+='<p class="text-ellipsis">'+'推送地址：'+arr.pushurl+'</p>':'');
		   		((arr.url && arr.url!='') ? bodyHtml+='<p class="text-ellipsis">'+'url：'+arr.url+'</p>':'');	
		   		((arr.key && arr.key!='') ? bodyHtml+='<p class="text-ellipsis">'+'Key：'+arr.key+'</p>':'');

		    }else{
		    	((arr.account && arr.account!='') ? bodyHtml+='<p>'+'账号：'+arr.account+'</p>':'');
		        ((arr.role && arr.role!='') ? bodyHtml+='<p>'+'角色：'+arr.role+'</p>':'');//用户显示角色	

		    }
              return bodyHtml;
		}
	})

})(jQuery);
var nowDate = function(){
	this.now=new Date();                  //当前日期
    this.nowDayOfWeek = this.now.getDay();         //今天本周的第几天
    this.nowDay = this.now.getDate();              //当前日
    this.nowMonth = this.now.getMonth()+1;           //当前月
    this.nowYear = this.now.getFullYear();

}
function dialog_close(){
	$(".close-btn").click(function(){
        BJUI.dialog('closeCurrent');
    })
}
function type_onversion(t){
    switch (t)
    {
    case 0:
      return "字节";
    case 1:
      return "整形";
    case 2:
      return "浮点型";
    case 3:
     return "字符串";
    }
}
function checkundefined(s){  

  if (s==undefined) {
    s="";
  }
  return s;
}

function jsonNotNull(data){
     for(var i in data){
      if(data[i]=='' || data[i]==null || data[i]==undefined){
        delete data[i];
      }
    }
    return data;
   }
function change_Width_Height(){
    var winHeight=0;
    var winWidth=0;
    if (window.innerHeight){
        winHeight = window.innerHeight;
    }else if ((document.body) && (document.documentElement.clientHeight)){
        winHeight = document.documentElement.clientHeight;
    }
    if (window.innerWidth){
        winWidth = window.innerWidth;
    }else if ((document.body) && (document.documentElement.clientWidth)){
        winWidth = document.documentElement.clientWidth;
    }
    var topHeight = winHeight/2+((winHeight/2)*0.1);
    var leftWidth = winWidth/2-310;
    
    $('.content').css({"top":topHeight,"left":leftWidth});
}

function uuid() {
    var s = [];
    var hexDigits = "0123456789abcdef";
    for (var i = 0; i < 32; i++) {
        s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
    }
    s[14] = "4";  // bits 12-15 of the time_hi_and_version field to 0010
    s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1);  // bits 6-7 of the clock_seq_hi_and_reserved to 01
    s[8] = s[13] = s[18] = s[23];
 
    var uuid = s.join("");
    return uuid;
}

function Trim(obj,str){
            var result;
            result = str.replace(/(^\s+)|(\s+$)/g,"");
            $(obj).val(result);
       }